package com.jjb.www.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.hjq.shape.layout.ShapeLinearLayout;
import com.hjq.shape.view.ShapeTextView;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.api.AetNumberFillInfoApi;
import com.jjb.www.http.api.AetNumberFillInfoV2Api;

/**
 * author : Android CRG
 * github : https://github.com/getActivity/AndroidProject
 * time   : 2018/11/05
 * desc   : 可进行拷贝的副本
 */
public final class MultipleChoiceV2Adapter extends AppAdapter<AetNumberFillInfoV2Api.Bean.QuestionAnswerDTO> {
    private int selPosition = -1;

    public MultipleChoiceV2Adapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {
        private ShapeLinearLayout mLlItem;
        private ShapeTextView mTvTitle;

        private ViewHolder() {
            super(R.layout.item_sing_choice);
            mLlItem = findViewById(R.id.ll_item);
            mTvTitle = findViewById(R.id.tv_title);
        }

        @Override
        public void onBindView(int position) {
            mTvTitle.setText(getItem(position).getOption());
//            if (position == selPosition) {
                if (getItem(position).isSelect()) {
                    mLlItem.getShapeDrawableBuilder()
                            .setSolidColor(ContextCompat.getColor(getContext(), R.color.color_EAF1FE))
                            .setStrokeColor(ContextCompat.getColor(getContext(), R.color.color_3675FE))
                            .setStrokeWidth(1)
                            .intoBackground();

                } else {
                    mLlItem.getShapeDrawableBuilder()
                            .setSolidColor(ContextCompat.getColor(getContext(), R.color.white))
                            .setStrokeColor(ContextCompat.getColor(getContext(), R.color.color_DCDCDC))
                            .setStrokeWidth(1)
                            .intoBackground();

                }

//            }
//            else {
//                mLlItem.getShapeDrawableBuilder()
//                        .setSolidColor(ContextCompat.getColor(getContext(), R.color.white))
//                        .setStrokeColor(ContextCompat.getColor(getContext(), R.color.color_DCDCDC))
//                        .setStrokeWidth(1)
//                        .intoBackground();
//            }
        }
    }

    public void setItemSel(int selPosition) {
        this.selPosition = selPosition;
        notifyDataSetChanged();
    }
}